package com.domor.xxx.system.service;

import com.domor.xxx.common.core.text.Convert;
import com.domor.xxx.system.domain.SysMsg;
import com.domor.xxx.system.mapper.SysMsgMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <h3>系统消息 服务层</h3>
 * @author liyuyang
 * @date 2020/5/15
 **/
@Service
public class SysMsgService {

    @Autowired
    private SysMsgMapper msgMapper;

    /**
     * 查询消息列表
     */
    public List<SysMsg> selectList(SysMsg msg) {
        return msgMapper.selectList(msg);
    }

    /**
     * 查询个人未读消息数量
     */
    public int countUnRead(String receiver) {
        return msgMapper.countUnRead(receiver);
    }

    /**
     * 插入系统消息
     */
    public int insert(SysMsg msg) {
        return msgMapper.insert(msg);
    }

    /**
     * 插入系统消息
     */
    public int batchInsert(List<SysMsg> msg) {
        return msgMapper.batchInsert(msg);
    }

    /**
     * 根据ID批量修改消息状态
     */
    public int readMsgByIds(String ids) {
        return msgMapper.readMsgByIds(Convert.toStrArray(ids));
    }

    /**
     * 把接收人的所有消息设置为已读
     */
    public int readMsgByReceiver(String receiver) {
        return msgMapper.readMsgByReceiver(receiver);
    }

    /**
     * 把接收人的所有消息设置为已发送
     */
    public int sentMsgByReceiver(String receiver) {
        return msgMapper.sentMsgByReceiver(receiver);
    }

    /**
     * 把消息设置为已发送
     */
    public int sentMsgById(int msgId) {
        return msgMapper.sentMsgById(msgId);
    }

}
